import axios from "axios"
var baseURLStr = "http://127.0.0.1:3000";
const request = axios.create({
	baseURL: baseURLStr,
    timeout: 1000
})
request.interceptors.request.use(config => {
    if (config.method === 'GET' || config.method === 'get') {
        config.data = {unused: 0}
    }
    if (config.type === 'upload') {
        config.headers['Content-Type'] = 'multipart/form-data;'
    } else if(config.type === 'download') {
        config.responseType = 'arraybuffer'
    }else {
        config.headers['Content-Type'] = 'application/json;charset=utf-8'
    }
    return config
}, error => {
    return Promise.reject(error);
})
request.interceptors.response.use(config => {
    return config
},
    error => {
        if (error && error.response && error.response.status) {
            switch (error.response.status) {
                case 401:
					ElMessage.error('Token过期')
							document.cookie = "token=;Path=/ ";
							window.open('/login',_self)
					
                    break;
                case 500:
                    ElMessage.error(error.response.data.msg);
                    break;
                case 404:
                    ElMessage.error(error.response.data.msg);
                    break;
                default:
                    break;
            }
        }
    })
export default request
